{extend name="public:layout" /}
{block name="title"}线索详情{/block}
{block name="head"}
<style>
    body{background:#e8e8e8;}
    .leads-info-box{  position: fixed;width:100%;z-index:99;  top:0;  }
    .timeline{margin-top:189px;}
</style>
<link rel="stylesheet" href="/public/home/plugins/dropload/dropload.css">
{/block}
{block name="body"}
<!--线索详情头部-->
<div class="leads-info-box" id="leadInfo" >


</div>
<!--时间轴-->
<div id="record-list">
    <ul class="timeline" id="timeline">
    </ul>
</div>

{/block}
{block name="script"}
<script src="/public/home/plugins/dropload/dropload.min.js"></script>
<script type="text/html" id="leadsInfo-tpl">
    <div class="info-box" >
        <div class="thumb">
            <img src="/public/home/plugins/crm_app/img/head_img/head_img_01.png" alt="">
        </div>
        <h2 class="name">客户合同：{{ data.name }}<span class="sex">{{ data.sex }}</span></h2>
        <span class="mobile">客户名称：{{ data.mobile }}</span>
        <p class="info">预计成交金额：{{ data.create_time }}
            {{ if data.record_count!='' }}跟进：{{ data.record_count }}次<br>预计成交日期：{{ data.last_time }} 跟进人:{{ data.last_name }}<br>
            销售阶段{{ /if }}</p>
    </div>
    <div class="action-box">
        <ul class="am-avg-sm-3">
            <li>
                <a href="tel:{{ data.mobile }}" class="action-link bg-color1">
                    <span class="iconfont icon-iconfontphone"></span> 拨打电话
                </a>
            </li>
            <li>
                <a href="{:url('home/Index/index',['folder'=>'leads','file'=>'follow'])}&leads_id={{ data.leads_id }}" class="action-link bg-color2">
                    <span class="iconfont icon-xinzeng"></span> 跟进记录
                </a>
            </li>
            <li>
                <a href="{:url('home/Index/index',['folder'=>'business','file'=>'add'])}&leads_id={{ data.leads_id }}" class="action-link bg-color3">
                    <span class="iconfont icon-shangji"></span> 升级为商机
                </a>
            </li>
        </ul>
    </div>
</script>
<script type="text/html" id="record-tpl">
{{ each data as value }}
<li class="item">
    <div class="time-box">
        <span class="date">{{ value.date }}</span>
        <span class="time">{{ value.time }}</span>
        <span class="node"></span>
    </div>
    <div class="item-main">
        <div class="info-box">
            <h2 class="info-title">{{ value.record_title }} <span class="sub">跟进人：{{ value.name }}</span></h2>
            <p class="info">
                {{ value.record_remark }}
            </p>
            <div class="sound-box"></div>
            <div class="action-box"><a href="javascript:;" class="comment"><i class="iconfont icon-crmtubiao25"></i> 评论</a></div>
        </div>
    </div>
</li>
{{ /each }}
</script>
<script>
    $(function () {
        var leads_id="{$Request.param.leads_id}";
        console.log(leads_id);
        if(leads_id!=''){
            $.post("{:url('home/Leads/getOneInfo')}",{leads_id:leads_id},function (res) {
                if(res.status==2){
                    layerMsg('线索信息不存在',function () {
                        location.href="{:url('home/Index/index',['folder'=>'leads','file'=>'list'])}";
                    })
                }else{
                   console.log(res);
                   var html=template('leadsInfo-tpl',{data:res.data});
                   $('#leadInfo').empty().html(html);
                }
            })
        }
        dd.ready(function () {
            dd.biz.navigation.setRight({
                show: true,//控制按钮显示， true 显示， false 隐藏， 默认true
                control: true,//是否控制点击事件，true 控制，false 不控制， 默认false
                text: '跟进线索',//控制显示文本，空字符串表示显示默认文本
                onSuccess : function(result) {
                    location.href="{:url('home/Index/index',['folder'=>'leads','file'=>'follow'])}"+'&leads_id='+leads_id;
                },
                onFail : function(err) {}
            });
        })
        /**/
        document.addEventListener('backbutton', function(e) {
            layerMsg('哈哈哈');
            e.preventDefault(); //backbutton事件的默认行为是回退历史记录，如果你想阻止默认的回退行为，那么可以通过preventDefault()实现
        });
        /**/
        // 页数
        var data = {
            page: 0,
            leads_id:leads_id
        };
        // dropload
        var drop = $('#record-list').dropload({
            scrollArea: window,
            domUp : {
                domClass   : 'dropload-up',
                domRefresh : '<div class="dropload-refresh">↓下拉刷新</div>',
                domUpdate  : '<div class="dropload-update">↑释放加载内容</div>',
                domLoad    : '<div class="dropload-load"><span class="loading"></span>加载中...</div>'
            },
            domDown : {
                domClass   : 'dropload-down',
                domRefresh : '<div class="dropload-refresh">↑上拉加载更多</div>',
                domLoad    : '<div class="dropload-load"><span class="loading"></span>加载中</div>',
                domNoData  : '<div class="dropload-noData">内容加载完毕</div>'
            },
            loadUpFn:function (me) {
                data.page = 1;
                $.ajax({
                    url: "{:url('home/Leads/getRecord')}",
                    data: data,
                    success: function(res){
                        console.log(1);
                        console.log(res);
                        var result = '';
                        var html = template('record-tpl',{data:res.data.data});
                        // 为了测试，延迟1秒加载
                        setTimeout(function(){
                            $('#timeline').empty().append(html);
                            // 每次数据加载完，必须重置
                            me.resetload();
                            // 解锁loadDownFn里锁定的情况
                            me.unlock();
                            me.noData(false);
                        },1000);
                    },
                    error: function(xhr, type){
                        alert('Ajax error!');
                        // 即使加载出错，也得重置
                        me.resetload();
                    }
                });
            },
            loadDownFn: function (me) {
                data.page++;
                // 拼接HTML
                var result = '';
                $.ajax({
                    url: "{:url('home/Leads/getRecord')}",
                    data: data,
                    success: function (res) {
                        console.log(2);
                        console.log(res);
                        if (data.page >= res.data.last_page) {
                            // 锁定
                            me.lock();
                            // 无数据
                            me.noData();
                        }
                        var html = template('record-tpl', {data:res.data.data});
                        $('#timeline').append(html);
                        me.resetload();
                        if(res.data.data.length<4){
                            $('.dropload-noData').remove();
                        }
                    },
                    error: function (xhr, type) {
                        layer.open({
                            content: '加载出错'
                            , skin: 'msg'
                            , time: 2 //2秒后自动关闭
                        });
                        // 锁定
                        me.lock();
                        // 无数据
                        me.noData();
                        me.resetload();
                    }
                });
            }
        });

    })
</script>
{/block}